package anthology.daily_question._24_11;

import java.util.Arrays;

//https://leetcode.cn/problems/find-the-power-of-k-size-subarrays-i/description/?envType=daily-question&envId=2024-11-06
public class _3254长度为K的子数组的能量值1 {
    //枚举
    class Solution {
        public int[] resultsArray(int[] nums, int k) {
            int len = nums.length;
            int[] ans = new int[len-k+1];
            Arrays.fill(ans,-1);
            for(int i=0; i<=len-k; i++){
                boolean falg = true;
                for(int j=i+1; j<i+k; j++){
                    if(nums[j]-nums[j-1] != 1){
                        falg = false;
                        break;
                    }
                }
                if(falg)
                    ans[i] = nums[i+k-1];
            }
            return ans;
        }
    }
    //统计长度
    class Solution2 {
        public int[] resultsArray(int[] nums, int k) {
            int n = nums.length;
            int[] ans = new int[n - k + 1];
            Arrays.fill(ans, -1);
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                cnt = i == 0 || nums[i] - nums[i - 1] != 1 ? 1 : cnt + 1;
                if (cnt >= k) {
                    ans[i - k + 1] = nums[i];
                }
            }
            return ans;
        }
    }
}
